<?php
require_once "site_config.php";
require_once "ra_global.php";
// 红包积分抽奖
$method = $_GET['method'];
if($method == "checkpopup"){
    $shopId = $_GET['shopid'];
    $userId = $_GET['userid'];
    $statYear = $_GET['year'];
    $statMonth = $_GET['month'];

    echo checkpopup($db, $shopId, $userId, $statYear, $statMonth);
}

function checkpopup($db, $shopId, $userId, $statYear, $statMonth) {
    $result = array();

    // 只有店长和店员可以兑换红包
    $encourageLog = $db->ig2_want('mae_sell_encourage_log','shopid = '.$shopId.' AND statyear = "'.$statYear.'" AND statmonth = "'.$statMonth.'"');
    if ($encourageLog) {
        // 已经提醒过的就不再提醒了
        $logDetail = $db->ig2_want('mae_sell_encourage_log_detail', 'logid = '.$encourageLog['id'].' AND userid = '.$userId);
        if (!$logDetail) {
            $db->ig2_query('INSERT INTO mae_sell_encourage_log_detail (logid, userid, createtime) VALUES ('.$encourageLog['id'].', '.$userId.', '.time().')');
            $result['status'] = 1;
            $result['addscore'] = $encourageLog['addscore'];
        } else {
            $result['status'] = 0;
        }
    } else {
        $result['status'] = 0;
    }

    return json_encode($result);
}
?>